<template>
  <div style="margin-left: 5px;margin-right: 5px;">
    <div style="margin-top: 1%;"></div>
    <!--查询表单-->
    <el-form :inline="true" class="demo-form-inline">
      <el-form-item label="算法属性">
        <el-input v-model="algorithmQuery.name" placeholder="算法名"/>
      </el-form-item>
      <el-form-item>
        <el-select v-model="algorithmQuery.typeId" clearable placeholder="算法类型">
          <el-option v-for="type in this.allAlgTypes" :key="type.id" :value="type.id" :label="type.typeName"/>
        </el-select>
      </el-form-item>
      <el-form-item label="添加时间">
        <el-date-picker v-model="algorithmQuery.begin" type="datetime" placeholder="选择开始时间"
                        value-format="yyyy-MM-dd HH:mm:ss" default-time="00:00:00"/>
      </el-form-item>
      <el-form-item>
        <el-date-picker v-model="algorithmQuery.end" type="datetime" placeholder="选择截止时间"
                        value-format="yyyy-MM-dd HH:mm:ss" default-time="00:00:00"/>
      </el-form-item>
      <el-button type="primary" icon="el-icon-search" @click="queryAlgorithm()">查询</el-button>
      <el-button type="default" @click="resetData()">清空</el-button>
    </el-form>
    <!-- 表格 -->
    <el-table :data="tableData" stripe border style="width: 100%">
      <el-table-column prop="name" label="算法名" width="auto">
      </el-table-column>
      <el-table-column prop="detail" label="算法介绍">
      </el-table-column>
      <el-table-column prop="algorithmAuthorName" label="作者">
      </el-table-column>
      <el-table-column prop="algorithmType" label="类型">
      </el-table-column>
      <el-table-column prop="teachUrl" label="教程链接">
      </el-table-column>
      <el-table-column prop="insertTime" label="添加时间">
      </el-table-column>
      <el-table-column label="操作" width="auto" align="center">
        <template slot-scope="scope">
          <el-button type="primary" size="mini" icon="el-icon-edit" @click="editAlgorithmById(scope.row.id)">编辑
          </el-button>
          <strong style="font-size: 24px;">|</strong>
          <el-button type="danger" size="mini" icon="el-icon-delete" @click="deleteAlgorithmById(scope.row.id)">删除
          </el-button>
        </template>
      </el-table-column>
    </el-table>
    <!-- 分页 -->
    <el-pagination background :current-page="page" :page-size="limit" :total="total"
                   style="padding: 30px 0; text-align: center;" layout="total, prev, pager, next, jumper"
                   @current-change="queryAlgorithm"/>
  </div>
</template>

<script>
  import algorithmApi from "../../../api/cby/algorithm";
  import algTypeApi from "../../../api/cby/algType";

  export default {
    data() {
      return {
        page: 1, // 当前页
        limit: 3, // 每页数量
        total: 0, // 总记录数
        algorithmQuery: {}, // 查询条件封装对象
        tableData: [],
        allAlgTypes: [],
      }
    },
    created() {
      this.queryAlgorithm()
      this.getAllTypes()
    },
    methods: {
      //根据条件查询并分页
      queryAlgorithm(page = 1) {
        this.page = page
        algorithmApi.getAlgorithmListPage(this.page, this.limit, this.algorithmQuery)
          .then((response) => {
            // 请求成功
            console.log("成功")
            this.tableData = response.data.rows;
            this.total = response.data.total;
          })
          .catch((error) => {
            console.log(error);
          });
      },
      /*//查询所有算法信息，用于测试
      queryAlgorithmWithNoWrapper(page = 1) {
        this.page = page
        algorithmApi.getAlgorithmList()
          .then((response) => {
            // 请求成功
            this.tableData = response.data.algorithmDisplayList;
          })
          .catch((error) => {
            console.log(error);
          });
      },*/

      resetData() {
        this.queryAlgorithm = {}
      },

      //获取所有算法类型
      getAllTypes() {
        algTypeApi.getAllTypes()
          .then((response) => {
            // 请求成功
            this.allAlgTypes = response.data.allAlgTypes;
          })
          .catch((error) => {
            console.log(error);
          });
      },

      editAlgorithmById(rowId) {

      },

      deleteAlgorithmById(rowId) {

      },
    }
  }
</script>

<style>
</style>
